package org.dromara.common.mqtt.config;

import lombok.extern.slf4j.Slf4j;
import org.dromara.common.mqtt.client.EmqClient;
import org.dromara.common.mqtt.config.properties.MqttProperties;
import org.dromara.common.mqtt.listener.MqttTopicListener;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@AutoConfiguration
@Configuration
@EnableConfigurationProperties(MqttProperties.class)
@Slf4j
public class MqttConfig {

    @Bean
    public String connectServer(EmqClient emqClient){
        log.info("连接mqtt服务器");
        emqClient.init();
        emqClient.connect("admin", "admin123");
        return "Connected";
    }

    @Bean
    public MqttTopicListener mqttTopicListener(EmqClient emqClient) {
        return new MqttTopicListener(emqClient);
    }
}
